package com.weixin.gong.example.guava;

import com.google.common.collect.Sets;
import org.junit.Assert;
import org.junit.Test;

import java.util.Set;

/**
 * @author weixin.gong
 * @date 17-5-5 下午7:01
 */
public class SetExample {

    private final Set<String> set1 = Sets.newHashSet("1", "2");
    private final Set<String> set2 = Sets.newHashSet("3" , "2");

    @Test
    public void difference() {
        System.out.println("1对2的差集,difference:" + Sets.difference(set1, set2));
        Assert.assertArrayEquals(new String[]{"1"}, Sets.difference(set1, set2).toArray());
    }

    @Test
    public void intersection() {
        System.out.println("1和2的交集,intersection:" + Sets.intersection(set1, set2));
        Assert.assertArrayEquals(new String[]{"2"}, Sets.intersection(set1, set2).toArray());
    }

    @Test
    public void union() {
        System.out.println("1和2的并集,union:" + Sets.union(set1, set2));
        Assert.assertArrayEquals(new String[]{"1", "2", "3"}, Sets.newTreeSet(Sets.union(set1, set2)).toArray());

    }
}
